package org.pub.fast.jdbc.cross;

import java.sql.SQLException;
import java.util.ListResourceBundle;
import java.util.MissingResourceException;

public class ExceptionFactory {
	 private static ListResourceBundle MESSAGES = new Messages();
     public static SQLException getSQLException(String sqlstate,String param) {
        return getSQLException(sqlstate,param,null);
    }
    public static SQLException getSQLException(String sqlstate,String param,Throwable th) {
        String message;
        try {

            message=MESSAGES.getString(sqlstate);
        } catch(MissingResourceException e) {
            message="Resource not found: "+sqlstate;
        }
        if(param!=null) {
            message+=": "+param;
        }
        return new CrossDBSQLException(message,sqlstate,th);
    }
    /**
     * Gets the SQL Exception object for a specific SQLState.
     *
     * @param sqlstate - the SQL State
     * @return the SQLException object
     */
    public static SQLException getSQLException(String sqlstate) {
        return getSQLException(sqlstate,null);
    }
    public static SQLException getUnsupportedException() {
        return getSQLException(Messages.FEATURE_NOT_SUPPORTED);
    }
    public static SQLException getGeneralException(String param) {
        return getSQLException(Messages.GENERAL_ERROR,param);
    }
    public static SQLException getInvalidValueException(String param) {
        return getSQLException(Messages.INVALID_VALUE,param);
    }
    public static SQLException getClosedException() {
        return getSQLException(Messages.OBJECT_CLOSED);
    }
}
